package cn.tedu._05weibo.base.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.concurrent.TimeUnit;

/**
 * @Author Justin Parker
 * @Date 2024/8/19 0019 17:49
 * @Version 1.0
 */
@Component
public class CacheUtil {

    @Autowired
    private RedisTemplate<String, Serializable> redisTemplate;


    //字符串set方法
    public void set(String key, Serializable value) {
        redisTemplate.opsForValue().set(key, value);
    }

    //字符串setExpire方法
    public void setExpire(String key, Serializable value,long expire) {
        redisTemplate.opsForValue().set(key, value, expire, TimeUnit.SECONDS);
    }

    //字符串get方法
    public Serializable get(String key) {
        return redisTemplate.opsForValue().get(key);
    }
}
